import java.util.ArrayList;
import java.util.Random;


public class ChargeWheel {
        
		public final int CHARGECAP = 5;
        public int[] charges;
        enum chargeType{PASSION,ETHICS,DECEPTION,LOGIC};
        
        public ChargeWheel(){
                charges = new int[4];
                for(int i=0;i<charges.length;i++) charges[i]=0;
        }
        
        public void destroyRandomCharge(){
                Random rand= new Random(System.currentTimeMillis());
                ArrayList<Integer> chargelist = new ArrayList<Integer>();
                for(int i=0; i<4; i++){
                	for(int j=0; j<charges[i]; j++){
                		chargelist.add(i);
                	}
                }
                if (chargelist.size() > 0)
                {
                	int index = rand.nextInt(chargelist.size());
                	charges[chargelist.get(index)]--;
                }
        }
        
        public void gainRandomCharge(){
                Random rand= new Random(System.currentTimeMillis());
                int check = 0;
                for(int i=0; i< charges.length; i++){
                	if(charges[i] >= CHARGECAP) check++;
                }
                if(check >= 4) return;
                boolean loop = true;
                do{
                	int index= rand.nextInt(4);
                	if(charges[index] < CHARGECAP){charges[index]++; loop=false;}
                }while(loop);
        }
        
        public int getCharge(chargeType charge){
                int result = 0;

                switch(charge){
                case PASSION:
                        result= charges[0];
                        break;
                case ETHICS:
                        result= charges[1];
                        break;
                case DECEPTION:
                        result= charges[2];
                        break;
                case LOGIC:
                        result= charges[3];
                        break;
                }
                
                return result;
        }
        
        public void spendCharge(chargeType charge){
            switch(charge){
            case PASSION:
                    charges[0] -= 2;
                    break;
            case ETHICS:
                    charges[1] -= 2;
                    break;
            case DECEPTION:
                    charges[2] -= 2;
                    break;
            case LOGIC:
                    charges[3] -= 2;
                    break;
            }
            
    }
        
        public void setCharge(chargeType charge, int newAmount){
                switch(charge){
                case PASSION:
                        charges[0]=newAmount;
                        break;
                case ETHICS:
                        charges[1]=newAmount;
                        break;
                case DECEPTION:
                        charges[2]=newAmount;
                        break;
                case LOGIC:
                        charges[3]=newAmount;
                        break;
                }
        }
        
        public void incrementCharge(chargeType charge){
                switch(charge){
                case PASSION:
                        charges[0]++;
                        if(charges[0]>CHARGECAP) charges[0]=CHARGECAP;
                        break;
                case ETHICS:
                        charges[1]++;
                        if(charges[1]>CHARGECAP) charges[1]=CHARGECAP;
                        break;
                case DECEPTION:
                        charges[2]++;
                        if(charges[2]>CHARGECAP) charges[2]=CHARGECAP;
                        break;
                case LOGIC:
                        charges[3]++;
                        if(charges[3]>CHARGECAP) charges[3]=CHARGECAP;
                        break;
                }
        }
        
        public void reset()
        {
        	for(int i=0;i<charges.length;i++) charges[i]=0;
        }
}
